﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HanGu.Services.Interface;
using HanGu.Entity;
namespace HanGu.Services
{
    public class SystemConfigService : BaseService, ISystemConfig
    {

        public List<SystemConfig> GetAll()
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.SystemConfig.ToList();
            }
        }

        public List<SystemConfig> GetAll(UniversallySearchParam searchparma)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                var query = obj.SystemConfig.Where(c => 1 == 1);
                if (!string.IsNullOrEmpty(searchparma.Ttile))
                {
                    query = query.Where(c => c.Title.IndexOf(searchparma.Ttile) >= 0);
                }
                if (!string.IsNullOrEmpty(searchparma.Lectcher))
                {
                    query = query.Where(c => c.Key == searchparma.Lectcher);
                }
                query = base.Paging<SystemConfig>(query, searchparma.Pagination);

                return query.ToList();
            }
        }

        public SystemConfig GetByID(string key)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.SystemConfig.Where(c => c.Key == key).FirstOrDefault();
            }
        }


        public bool Add(SystemConfig model)
        {
            try
            {
                this.Add<SystemConfig>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Update(SystemConfig model)
        {
            try
            {
                this.Update<SystemConfig>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Delete(string key)
        {
            try
            {
                this.Delete<SystemConfig>(c => c.Key == key);
                return true;
            }
            catch { return false; }
        }


    }
}
